﻿using System.Collections;
using Gp.Scripts.Core;
using Gp.Scripts.Data.Skills;
using Gp.Scripts.Equip;
using Gp.Scripts.GUI;

namespace Gp.Scripts.Core {
    public class CounterAttackReactionWrapper : ReactionRegister<AttackPreReaction> {
        public CounterAttackReactionWrapper(BaseUnit unit) : base(unit) { }

        protected override bool CanPerform(AttackPreReaction arg) {

            return arg.Target == Unit
                   && RuleJudge(arg)
                   && WeaponJudge(arg)
                   && ResourceJudge(arg)
                ;
        }

        private bool ResourceJudge(AttackPreReaction arg) {
            return Unit.ComCost.CheckResource(CostField.Reaction);
        }


        private bool WeaponJudge(AttackPreReaction args) {
            var targetWeapon = args.Target.ComEquip.CurWeapon;

            return false;
            // 攻击方使用近战武器
            // args.Attacker.ComEquip.CurWeapon.Config.GetWeaponType().WeaponBasicType == WeaponBasicType.Melee 

            // 单位使用远程武器
            // && targetWeapon.Config.GetWeaponType().WeaponBasicType == WeaponBasicType.Ranged

            // 远程武器满足攻击条件
            // && targetWeapon.Info.CanAttack();
        }






        /// <summary>
        /// 机制判断。
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        private bool RuleJudge(AttackPreReaction arg) {
            // 攻击者使用“冲锋” 或 攻击目标带有 “快速射击” 标签 
            return arg.IsCharging || arg.Tags.Contains(SkillTags.FastCounter);
        }
        
        
        
        

        protected override void OnRender(AttackPreReaction arg, ReactionRenderInfo info) {
            info.Title = "反制射击";
        }

        protected override IEnumerator OnTrigger(AttackPreReaction arg) {
            Global.Get<GridBattleGUISystem>().PlayFloatingText(arg.Target, "反制射击");

            Unit.ComCost.ReduceResource(CostField.Reaction);
            yield return Unit.ComSkill.ExecuteAttack(new AttackContext(arg.Attacker));
        }
    }
}